package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author luo20
 * @description 针对表【shopping_cart(购物车)】的数据库操作Mapper
 * @createDate 2025-07-21 23:06:57
 * @Entity com.sky.entity.ShoppingCart
 */
public interface ShoppingCartMapper extends BaseMapper<ShoppingCart> {
    /**
     * 根据套餐id或菜品id和菜品口味或用户id查询购物车数据是否存在
     *
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> list(ShoppingCart shoppingCart);

    /**
     * 更新购物车套餐或菜品数量
     *
     * @param shoppingCart
     * @return
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    Integer updateCartNumberById(ShoppingCart shoppingCart);

    /**
     * 插入购物车数据
     *
     * @param shoppingCart
     * @return
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{amount}, #{createTime})")
    Integer insertCart(ShoppingCart shoppingCart);

    /**
     * 删除购物车数据
     *
     * @param shoppingCart
     * @return
     */
    Integer delCart(ShoppingCart shoppingCart);

    /**
     * 批量保存购物车数据
     * @param shoppingCartList
     * @return
     */
    Integer saveBatch(@Param("shoppingCartList") List<ShoppingCart> shoppingCartList);
}




